<?php
//禁止报错
error_reporting(E_ERROR | E_WARNING | E_PARSE);

require_once "config.php";
require_once "autoload.php";

$app = $_GET['app'];

switch ($app) {
    default: {
        echo '请求非法！';
        break;
    }

    case 'QueryPhone': {
        $phone = $_GET['phone'];

        $info = app\QueryPhone::query($phone);

        $date = array();
        if ($info) {
            $date = $info;
            $date['code'] = 200;
        } else {
            $date['code'] = 400;
            $date['msg'] = '号码不正确！';
        }
        echo json_encode($date, JSON_UNESCAPED_UNICODE);

        break;
    }

    case 'QueryIP': {
        $ip = $_GET['ip'];

        $info = app\QueryIP::query($ip);

        $date = array();
        if ($info) {
            $date = $info;
            $date['code'] = 200;
        } else {
            $date['code'] = 400;
            $date['msg'] = 'IP地址不正确！';
        }
        echo json_encode($date, JSON_UNESCAPED_UNICODE);

        break;
    }

    case 'ShortURL': {
        $url_long = $_GET['url'];
        $info = app\ShortURL::query($url_long);
        if ($info) {
            $date = $info;
            $date['code'] = 200;
        } else {
            $date['code'] = 400;
            $date['msg'] = '网址不正确！';
        }
        echo json_encode($date, JSON_UNESCAPED_UNICODE);

        break;
    }

    case 'MyIP': {
        $ip = app\MyIP::query();
        $date['ip'] = $ip;
        echo json_encode($date, JSON_UNESCAPED_UNICODE);
        break;
    }
    
}


